package core

import (
	"cms/core/config"
	"cms/utils/convert"
	_ "github.com/go-sql-driver/mysql"
	"github.com/wdaglb/korm"
)

func InitDb()  {
	c := korm.NewConnect(korm.Config{
		DefaultConn: "default",
		MaxIdleConns: 100,
		MaxOpenConns: 20,
		ConnMaxLifetime: 3600 * 6,
	})

	err := c.AddDb(korm.DbConfig{
		Conn: "default",
		Driver: "mysql",
		Host:     config.Database.Host,
		Port:     convert.StrToInt(config.Database.Port),
		Database: config.Database.Database,
		User:     config.Database.Username,
		Pass:     config.Database.Password,
	})
	if err != nil {
		panic(err)
	}
}
